package com.yjhb.android.sbz.tool;

import android.text.TextUtils;

import com.yjhb.android.sbz.App;
import com.jojo.android.zxlib.tool.ZxClipboardTool;
import com.jojo.android.zxlib.tool.ZxEncodeTool;

import java.io.UnsupportedEncodingException;

/**
 * 创建者 zx
 * 创建时间 2020/12/3 10:07
 */
public class InvitationCodeTool {
    private final String TAG = "InvitationCode";

    private static String invitationCode = "";

    /**
     * 生成一个加密的邀请码
     *
     * @return
     */
    public static String generateCode() {
        if (App.userInfo == null) return "";
//        Map<String, String> map = new HashMap<>();
//        map.put("package", ZxAppTool.getAppPackageName(App.getInstance()));
//        map.put("code", App.userInfo.getId());
        try {
            return ZxEncodeTool.base64Encode2String(App.userInfo.getId().getBytes("utf-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return "";
//        return ZxEncryptTool.encode(App.userInfo.getId()).toLowerCase();
    }

    /**
     * 从剪切板获得一个邀请码
     *
     * @return
     */
    public static String getInvitationCode() {
        try {
            if (!TextUtils.isEmpty(invitationCode)) {
                return invitationCode;
            }
            CharSequence charSequence = ZxClipboardTool.getText(App.getInstance());
            if (charSequence == null) return null;
            String i = new String(ZxEncodeTool.base64Decode(charSequence.toString()), "utf-8");
            Integer code = Integer.parseInt(i);
            return invitationCode = "" + code;
        } catch (Exception e) {
        }
        return null;
    }

}
